<template>
  <div>
    <!-- 搜索筛选操作栏 -->
    <div class="filter-container clearfix">
      <el-select
        v-model="listQuery.type"
        style="width: 120px"
        class="filter-item"
      >
        <el-option label="手机号" value="user" />
        <el-option label="姓名" value="name" />
      </el-select>
      <el-input
        v-model="listQuery.value"
        placeholder="请输入"
        style="width: 200px; margin-left: 10px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-button
        v-waves
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        style="margin-left: 10px"
        @click="handleFilter"
      >
        搜索
      </el-button>
    </div>

    <!-- 表格 -->
    <el-table
      :key="tableKey"
      ref="table"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column label="手机号" prop="user" align="center" />
      <el-table-column label="姓名" align="center" prop="name" />
    </el-table>
  </div>
</template>

<script>
import { getMemberList } from '@/api/common'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  components: {
    Pagination
  },
  directives: {
    waves
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      listLoading: false,
      listQuery: {
        page: 1,
        per_page: 20,
        value: undefined,
        type: 'user'
      }
    }
  },
  methods: {
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    getList() {
      if (!this.listQuery.value) {
        this.$message.warning('请输入搜索内容')
        return false
      }
      this.listLoading = true
      // let params = { status: 0 };
      const params = {}
      params[this.listQuery.type] = this.listQuery.value
      getMemberList(params)
        .then((response) => {
          this.list = response.data.data
          this.$emit('search', response.data.data)
        })
        .finally(() => {
          this.listLoading = false
        })
    }
  }
}
</script>
